package com.donggei.exp3.dao.impl;

import com.donggei.exp3.dao.IUserDao;
import com.donggei.exp3.pojo.User;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class UserDaoImpl implements IUserDao {

    private List<User> users = new ArrayList<User>();

    public UserDaoImpl() {
        super();
        users.add(new User(1, "user_name_1", "note_1"));
        users.add(new User(2, "user_name_2", "note_2"));
        users.add(new User(3, "user_name_3", "note_3"));

    }

    @Override
    public User getUser(Integer id) {
 
        for (User user : users) {
            if (user.getId() == id) {
                return user;
            }
        }
        return null;
    }

    @Override
    public Boolean insertUser(User user) {
 
        Boolean flag = false;
        System.out.println(user.getId()+ ">>" +user.getUserName() + ">>" + user.getNote());
        users.add(user);
        flag = true;
        return flag;
    }

    @Override
    public List<User> findAllUser() {
 
        return users;
    }
}